// pages/teamEntry/teamEntry.js
var that,
  app = getApp(),
  api = new (require('../../utils/api.js')),
  util = new (require('../../utils/util.js')),
  headimg = api.getimgurl();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    orgcode: '',//机构代码
    contacts: '',//联系人
    phone: '',
    typename: '请选择公司类型',
    typeid: 0,//公司类型id
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this
    that.getdata()
  },
  getdata() {
    api.getCompanytype(res => {
      if (res.data.issuccess == 1) {
        let { list } = res.data
        that.setData({ list })
      }
    })
  },

  settled() {
    let { name, orgcode, contacts, phone, typeid } = that.data, err = ''
    if (phone.length != 11) err = '请输入正确的手机号'
    if (phone == '') err = '请输入手机号'
    if (contacts == '') err = '请输入联系人'
    if (orgcode == '') err = '请输入机构代码'
    if (name == '') err = '请输入公司名称'
    if (typeid == 0) err = '请输入公司类型'
    if (err.length > 0) {
      wx.showToast({
        title: err,
        icon: 'none'
      })
      return
    }
    wx.showLoading({
      title: '提交中...',
    })
    api.addSettledcompany({ name, orgcode, contacts, phone, typeid}, res => {
      if (res.data.issuccess == 1) {
        wx.hideLoading()
        wx.showModal({
          title: '提示',
          content: '提交成功',
          success(res) {
            if (res.confirm) {
              wx.navigateBack()
            }
          }
        })
      } else {
        wx.showModal({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },
  inputtap(e) {
    let { prop } = e.currentTarget.dataset
    that.setData({ [prop]: e.detail.value })
  },
  changeType(e){
    let {list} = that.data,{value} = e.detail
    that.setData({typename:list[value].name,typeid:list[value].id})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})